Holds information, and controls, over a function in a scripting environment. More...
Public Member Functions | |
OutputValue | defaultFunction (const DataStack &stack) |
The default place holder function. Set by default. | |
Function (const char *name) | |
virtual | ~Function () |
const char * | getName () const |
void | addParameter (FUNCTION_PARAMETER_TYPE type, const char *userTypeName="") |
void | setFunction (FunctionCallback function) |
void | reset () |
Holds information, and controls, over a function in a scripting environment.
Usage is to declare the function in the environment, sets its callback and parameters. Whenever a script will call the function, it will check and fill with parameter the stack and call the callback. Callback can then return whatever it needs to returns after processing, and this will be used within the environment.
Here is a high level overview of the usage :
Function* func = environment->setFunction("add") ; func->setCallback(addCallback) ; func->addParameter(FUNCTION_PARAMETER_TYPE::INT) ; func->addParameter(FUNCTION_PARAMETER_TYPE::STRING) ;
local x = add(5, "p") ;
OutputValue addCallback (const DataStack& stack) { int param0 = stack[0]._valInt ; const std::string& param1 = stack[1]._valString ; return OutputValue(param1 + std::to_string(param0)) ; }
print(x) ; > p5
nkScripts::Function::Function | ( | const char * | name | ) |
Constructor.
name | The name of the function. |
|
virtual |
Destructor.
const char* nkScripts::Function::getName | ( | ) | const |
void nkScripts::Function::addParameter | ( | FUNCTION_PARAMETER_TYPE | type, |
const char * | userTypeName = "" |
||
) |
Adds a parameter in the function signature.
type | The parameter type. |
userTypeName | If user data, the type awaited. |
void nkScripts::Function::setFunction | ( | FunctionCallback | function | ) |
Sets the callback function when this function is called in script.
function | The function to call. |
void nkScripts::Function::reset | ( | ) |
Resets and starts back from an empty function.